<?php

/**
 * This is the model class for table "bt_battery".
 *
 * The followings are the available columns in table 'bt_battery':
 * @property integer $RECORD_ID
 * @property integer $BASE_N
 * @property string $GROUP_V
 * @property integer $BATTERYTPYE_V
 * @property string $SERIAL_N
 * @property string $SETUP_D
 * @property string $CURDATE_D
 * @property integer $CREATE_USERID
 * @property string $STATUS_N
 * @property string $CURVAL_N
 * @property string $CURINNER_N
 * @property string $CUR_ELECTRIC_N
 * @property string $CUR_HL_INNER_N
 * @property string $FORCASTVOLUME_N
 * @property string $TESTVOLUME_N
 * @property string $POWERSUPPLY_N
 * @property string $BACKLOAD_N
 * @property string $REMARK_V
 */
class BtBattery extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return BtBattery the static model class
	 */
	
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'bt_battery';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('GROUP_V, SERIAL_N', 'required'),
			array('BASE_N, BATTERYTYPE_V', 'numerical', 'integerOnly'=>true),
			array('GROUP_V, REMARK_V', 'length', 'max'=>255),
			array('SERIAL_N', 'length', 'max'=>5),
			array('STATUS_N', 'length', 'max'=>2),
			//array('CURVAL_N, CURINNER_N, ', 'length', 'max'=>10),
			array('SETUP_D, CURDATE_D, SERIAL_N, BASE_N, CURVAL_N, CURDATE_D, TESTVOLUME_N, POWERSUPPLY_N, BACKLOAD_N, FORCASTVOLUME_N, REMARK_V', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('RECORD_ID, BASE_N, GROUP_V, BATTERYTYPE_V, SERIAL_N, SETUP_D, INSTALL_TIME, CURDATE_D, CREATE_USERID, STATUS_N, CURVAL_N, CURINNER_N, CUR_ELECTRIC_N, CUR_HL_INNER_N, CUR_TEMPERATURE_N, FORCASTVOLUME_N, TESTVOLUME_N, POWERSUPPLY_N, BACKLOAD_N, REMARK_V', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'base'=>array(self::HAS_ONE,'MtsysBase', ''),
			'batterys'=>array(self::BELONGS_TO, 'BtBatterys', 'GROUP_V'),
			'dictbattery'=>array(self::HAS_ONE, 'DictBattery', ''),
			'dictmanu'=>array(self::HAS_ONE, 'DictManufacturer', ''),
			'dictsort'=>array(self::HAS_ONE, 'DictBatterySort', ''),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'RECORD_ID' => '流水',
			'BASE_N' => '站点名',
			'GROUP_V' => '电池组',
			'BATTERYTYPE_V' => '电池规格',
			'SERIAL_N' => '电池序号',
			'SETUP_D' => '电池年代',
			'CURDATE_D' => '采集时间',
			'CREATE_USERID' => '创建人',
			'STATUS_N' => '单体电池状态',
			'CURVAL_N' => '当前电压(V)',
			'CURINNER_N' => '当前电阻(mΩ)',
			'CUR_ELECTRIC_N' => '电流(mA)',
			'CUR_HL_INNER_N' => '汇流排内阻(mΩ)',
			'CUR_TEMPERATURE_N' => '温度(℃)',
			'FORCASTVOLUME_N' => '预估容量(Ah)',
			'TESTVOLUME_N' => '电池测试放电容量(Ah)',
			'POWERSUPPLY_N' => '供电情况',
			'BACKLOAD_N' => '后备负载',
			'REMARK_V' => '备注',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('RECORD_ID',$this->RECORD_ID);
		$criteria->compare('BASE_N',$this->BASE_N);
		$criteria->compare('GROUP_V',$this->GROUP_V,true);
		$criteria->compare('BATTERYTYPE_V',$this->BATTERYTYPE_V);
		$criteria->compare('SERIAL_N',$this->SERIAL_N,true);
		$criteria->compare('SETUP_D',$this->SETUP_D,true);
		$criteria->compare('CURDATE_D',$this->CURDATE_D,true);
		$criteria->compare('CREATE_USERID',$this->CREATE_USERID);
		$criteria->compare('STATUS_N',$this->STATUS_N,true);
		$criteria->compare('CURVAL_N',$this->CURVAL_N,true);
		$criteria->compare('CURINNER_N',$this->CURINNER_N,true);
		$criteria->compare('CUR_ELECTRIC_N',$this->CUR_ELECTRIC_N,true);
		$criteria->compare('CUR_HL_INNER_N',$this->CUR_HL_INNER_N,true);
		$criteria->compare('FORCASTVOLUME_N',$this->FORCASTVOLUME_N,true);
		$criteria->compare('TESTVOLUME_N',$this->TESTVOLUME_N,true);
		$criteria->compare('POWERSUPPLY_N',$this->POWERSUPPLY_N,true);
		$criteria->compare('BACKLOAD_N',$this->BACKLOAD_N,true);
		$criteria->compare('REMARK_V',$this->REMARK_V,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}